package imu.g3.service;

import imu.g3.aspect.SystemLogAspect;
import imu.g3.dao.UserDao;
import imu.g3.dao.UserMapper;
import imu.g3.model.MyProjectUploadFiles;
import imu.g3.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public int register(User user){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String date = df.format(new Date());// new Date()为获取当前系统时间，也可使用当前时间戳
        user.setRegDate(date);
        int flag = userMapper.register(user);

        return flag;
    }

    public List<User> getUserInfo() {
        List<User> userList = userMapper.getUserInfo();
        return userList;
    }

    public void updateIconName(String username, String fileName) {
        userMapper.updateIconName(username,fileName);
    }


    public User loginSuccess(User user) {
        SystemLogAspect.getUser(user);
        return user;
    }
}
